-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow module without version #600
Conversation
@SteveL-MSFT I know you have a ton on your plate, but hopefully you have some time to check out this small change. If you want me to add a test, I can make a duplicate of the TestClassResource. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test
Tests have been included. If you need it in the config, let me know, thought I don't believe it is needed. |
9767de9
to
8edeb32
Compare
powershell-adapter/Tests/TestClassNoVersion/TestClassNoVersion.psd1
Outdated
Show resolved
Hide resolved
1a488e3
to
58b9d3d
Compare
Added the |
powershell-adapter/Tests/TestClassNoVersion/TestClassNoVersion.psd1
Outdated
Show resolved
Hide resolved
…sreyn/operation-methods into allow-module-without-version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, waiting on Andrew to review
# Get-Module -ListAvailable is slow and has a bug causing incorrect reporting | ||
$moduleFolders = Get-ChildItem $folder -Directory | ||
if (-not $moduleFolders) { | ||
$moduleFolders = Get-ChildItem (Split-Path $folder -Parent) | Where-Object { $_.Name -eq (Split-Path $folder -Leaf) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The -Depth 2
parameter in original code was supposed to handle both cases: modules with version subdirs and without.
Can you please give an example directory/module structure that was not handled correctly by old code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When working in the winget-dsc repository, I often found myself doing something like:
$env:PSModulePath += ";C:\source\winget-dsc\resources\Microsoft.DotNet.Dsc"
# Call function
Get-DscResourcesModules
# Old code did not list out the module
Hope that sheds some light on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please post an output of
Get-ChildItem -Recurse -Path C:\source\winget-dsc\resources\Microsoft.DotNet.Dsc | %{$_.FullName}
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you; in the right picture - what is the full path to NpmDsc.psd1
that is returned by Get-DSCResourceModules
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I got what's happening.
The module discovery in PowerShell (and consequently DSC PS adapter) requires that all module files should be in the module directory; and $env:PSModulePath
should point to the parent of that module directory.
In your case, the line should be:
$env:PSModulePath += ";C:\source\winget-dsc\resources"
rather than
$env:PSModulePath += ";C:\source\winget-dsc\resources\NpmDsc"
.
This should work with existing code. Please try it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, Andrew. I tried it in the past, and that works. But sometimes, I want only particular modules to be found, with the structure mentioned in this PR and in the test. What are your thoughts on those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gijsreyn I think the problem is that this is contrary to how module discovery works with PS7 and it would be preferable to not deviate from that. Is this only for development purposes or do you have a real scenario where you want to limit the discovery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can understand, and this was the use case. Feel free to abandon the pull request. I appreciated the time you guys looked into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @SteveL-MSFT. After testing for a while, I got a scenario that breaks the current testing cycle.
Imagine the following use case found while developing in winget-dsc. To test out both cases by either using Invoke-DscResource
or the class directly, we declare at the top of the test the using module
statement.
When modules are being discovered in the lower levels, so say C:\source\winget-dsc\resources\NpmDsc, it correctly loads the using module
statement, but it doesn't do it for PSDesiredStateConfiguration. If I now add it on higher level in the same call, I get an error stating:
PS C:\Users\User> $env:PSModulePath += ";C:\source\winget-dsc\resources\Microsoft.Windows.Setting.Language"
PS C:\Users\User> Get-DscResource
Exception: Exception setting "Module": "Cannot convert the "System.Object[]" value of type "System.Object[]" to type
"System.Management.Automation.PSModuleInfo"."
I know you've closed down the ticket, but perhaps we can still consider it. Thanks.
PR Summary
Allow modules that don't have a version directory to be added in
$env:PSModulePath
.PR Context
The
Get-DscResourceModules
function scans the$env:PSModulePath
to find relevant modules to be included in the cache. When a module doesn't have a version directory, it does not find the module. This change allows the ability to include modules that don't contain the directory.I added this change because it can be useful for testing purposes to see the participation of DSC resources when developing them. For example, take the
winget-dsc
repository. Simply adding the resource to the environment variable adds it for participation.